Passed
Pull Request — master (#22)
by
unknown
08:10 queued 04:20
created

SelectMapComponent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ngOnInit 0 2 1
A trackByFn 0 3 3
1
import { ValueAccessorBase } from './../abstract/ValueAccessorBase';
2
/**
3
   Copyright 2018 June Hanabi
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
 */
17
18
declare var window: {
19
    require: any;
20
}
21
22
import { Component, OnInit, Input } from '@angular/core';
23
24
import {
25
    NG_VALUE_ACCESSOR,
26
} from '@angular/forms';
27
28
import { GameDataService } from './../../data/gameData.service';
29
import { Map } from '../../../assets/data/maps.d';
30
31
const _: any = window.require("lodash");
32
33
@Component({
34
    selector: 'select-map',
35
    templateUrl: './select-map.component.pug',
36
    styleUrls: ['./select-map.component.scss'],
37
    providers: [
38
        { provide: NG_VALUE_ACCESSOR, useExisting: SelectMapComponent, multi: true }
39
    ],
40
})
41
export class SelectMapComponent extends ValueAccessorBase<string> implements OnInit {
42
43
    constructor(
44
        public gd: GameDataService
45
    ) {
46
        super();
47
    }
48
49
    ngOnInit() {
50
51
    }
52
53
    @Input()
54
    public disabled: boolean = false;
55
56
    @Input()
57
    public noneSelectable: boolean = false;
58
59
    @Input()
60
    public label: string = "Select Map";
61
62
    get mapList() {
63
        const maps: Map[] = this.gd.file("maps").data;
64
65
        let mapListNormal: Map[] = _.filter(maps, (value: Map) => {
66
            if (!value.glitch)
67
                return true;
68
69
            return false;
70
        });
71
72
        mapListNormal = _.sortBy(mapListNormal, ['name']);
73
74
        let mapListGlitch: Map[] = _.filter(maps, (value: Map) => {
75
            if (value.glitch)
76
                return true;
77
78
            return false;
79
        });
80
81
        mapListGlitch = _.sortBy(mapListGlitch, ['name']);
82
83
        return [
84
            { name: "--- Normal Maps ---", ind: 0x100, disable: true },
85
            ...mapListNormal,
86
            { name: "--- Glitch Maps ---", ind: 0x100, disable: true },
87
            ...mapListGlitch
88
        ];
89
    }
90
91
    trackByFn(index: number) {
92
        return index;
93
    }
94
}
95